home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Samples / SampleCode / GeometryTest / Textures.c < prev    next >
Encoding:
Text File  |  1997-08-14  |  3.3 KB  |  117 lines  |  [TEXT/MPCC]

  1. // routines to allow us to put texture maps on a parameterized group
  2.  
  3. #include <QuickDraw.h>
  4. #include "QD3D.h"
  5. #include "QD3DGroup.h"
  6. #include "QD3DShader.h"
  7.  
  8.  
  9. #include "PictRead.h"        // this is a library file from QD3D applications folder
  10. #include "Textures.h"
  11.  
  12. TQ3Status AddTextureToGroup( TQ3GroupObject    theGroup, TQ3StoragePixmap *textureImage)
  13. {
  14.     TQ3TextureObject    textureObject;
  15.     TQ3GroupPosition position;
  16.     TQ3Object        firstObject;
  17.     
  18.     textureObject = Q3PixmapTexture_New(textureImage);
  19.     
  20.     if( textureObject ) {
  21.         if( Q3Object_IsType(theGroup, kQ3GroupTypeDisplay) == kQ3True) {
  22.             Q3Group_GetFirstPosition(theGroup, &position);
  23.     
  24.             Q3Group_GetPositionObject(theGroup, position,    &firstObject);
  25.     
  26.             if( Q3Object_IsType(firstObject, kQ3SurfaceShaderTypeTexture) == kQ3True) {
  27.                 TQ3TextureObject    oldTextureObject;
  28.                 TQ3StoragePixmap oldTextureImage;
  29.                         
  30.                 Q3TextureShader_GetTexture(firstObject, &oldTextureObject);
  31.                 Q3PixmapTexture_GetPixmap(oldTextureObject, &oldTextureImage);
  32.                 
  33.                 Q3Object_Dispose(oldTextureObject);
  34.                 Q3TextureShader_SetTexture(firstObject, textureObject);
  35.                 Q3Object_Dispose(textureObject);
  36.             } else {
  37.                 TQ3ShaderObject textureShader;
  38.                 
  39.                 textureShader = Q3TextureShader_New(textureObject);
  40.                 Q3Object_Dispose(textureObject);
  41.                 //Q3Group_SetPositionObject(theGroup, position, theDocument->textureShader);
  42.                 Q3Group_AddObjectBefore(theGroup, position, textureShader);
  43.                 Q3Object_Dispose(textureShader);
  44.             }
  45.             
  46.             Q3Object_Dispose(firstObject);
  47.         } else if( Q3Object_IsType(theGroup, kQ3DisplayGroupTypeOrdered) == kQ3True) {
  48.             TQ3ShaderObject textureShader;
  49.             
  50.             Q3Group_GetFirstPositionOfType(
  51.                 theGroup,
  52.                 kQ3ShapeTypeShader, &position);    
  53.             
  54.             if( position ) {
  55.                 Q3Group_GetPositionObject(theGroup, position,    &firstObject);
  56.     
  57.                 if( Q3Object_IsType(firstObject, kQ3SurfaceShaderTypeTexture) == kQ3True) {
  58.                     TQ3TextureObject    oldTextureObject;
  59.                     TQ3StoragePixmap oldTextureImage;
  60.                     
  61.                     Q3TextureShader_GetTexture(firstObject, &oldTextureObject);
  62.                     Q3PixmapTexture_GetPixmap(oldTextureObject, &oldTextureImage);
  63.                     
  64.                     Q3Object_Dispose(oldTextureObject);
  65.                     Q3TextureShader_SetTexture(firstObject, textureObject);
  66.                     Q3Object_Dispose(textureObject);
  67.                 } else {
  68.                     textureShader = Q3TextureShader_New(textureObject);
  69.                     if( textureShader ) {
  70.                         Q3Object_Dispose(textureObject);
  71.                         Q3Group_SetPositionObject(theGroup, position, textureShader);
  72.                         Q3Object_Dispose(textureShader);
  73.                     } else {
  74.                         return(kQ3Failure);
  75.                     }
  76.                 }
  77.             } else {
  78.                 textureShader = Q3TextureShader_New(textureObject);
  79.                 if( textureShader ) {
  80.                     Q3Object_Dispose(textureObject);
  81.                     Q3Group_AddObject(theGroup, textureShader);
  82.                     Q3Object_Dispose(textureShader);
  83.                 } else {
  84.                     return(kQ3Failure);
  85.                 }
  86.             }
  87.             
  88.         }
  89.     return(kQ3Success);
  90.     } else {
  91.         return(kQ3Failure);
  92.     }
  93. }
  94.  
  95. void PictureFileToPixmap( TQ3StoragePixmap *bMap )
  96. {
  97.     PicHandle             thePicture = nil;
  98.     
  99.     if((thePicture = GetPICTFile()) != NULL ) {
  100.     
  101.         LoadMapPICT( thePicture, 
  102.                      0L,
  103.                      (unsigned long)((**thePicture).picFrame.right - (**thePicture).picFrame.left),
  104.                      (unsigned long)((**thePicture).picFrame.bottom - (**thePicture).picFrame.top),
  105.                      bMap)    ;
  106.         
  107.     }
  108. }
  109.  
  110. void TextureGroup( TQ3GroupObject    theGroup)
  111. {
  112.     TQ3StoragePixmap         myMap ;
  113.     
  114.     PictureFileToPixmap( &myMap ) ;
  115.     if( myMap.image != NULL )
  116.         AddTextureToGroup( theGroup, &myMap ) ;
  117. }